﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Graghics
{


    public interface Graghics
    {
        double op_space { get; set; }
        double freshSpace();//每当一个和面积有关的属性更改时，都更新面积
    }

    public class Square:Graghics
    {
        private double side,space;
        public Square()
        {
            side = 0;
            space = freshSpace();
        }
        public Square(double side)
        {
            this.side = side;
            space = freshSpace();
        }
        public double freshSpace()
        {
            if (side >= 0)
            {
                return side * side;
            }
            else
            {
                throw new Exception("error");
            }
        }
        public double op_side
        {
            get
            {
                return side;
            }
            set
            {
                if (value >= 0)
                {
                    side = value;
                    space = freshSpace();//同时更新面积
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
        public double op_space
        {
            get
            {
                return space;
            }
            set
            {
                if (value >= 0)
                {
                    space = value;
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
    }
    public class Rectangle:Graghics
    {
        private double length, width, space;
        public Rectangle()
        {
            length = 0;
            width = 0;
            space = freshSpace();
        }
        
        public Rectangle(double length,double width)
        {
            this.length = length;
            this.width = width;
            space = freshSpace();
        }
        public double freshSpace()
        {
            if (length < 0 || width < 0)
            {
                throw new Exception("error");
            }
            if (length >= 0 && width >= 0)
            {
                return length * width;
            }
            return 0;
        }
        public double op_length
        {
            get
            {
                return length;
            }
            set
            {
                if (value >= 0)
                {
                    length = value;
                    space = freshSpace();
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
        public double op_width
        {
            get
            {
                return width;
            }
            set
            {
                if (value >= 0)
                {
                    width = value;
                    space = freshSpace();
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
        public double op_space
        {
            get
            {
                return space;
            }
            set
            {
                if (value >= 0)
                {
                    space = value;
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
    }
    public class Circular : Graghics
    {
        private const double pai = 3.14;
        private double radius,space;
        public Circular()
        {
            radius = 0;
            space = freshSpace();
        }
        public Circular(double radius)
        {
            this.radius = radius;
            space = freshSpace();
        }
        public double freshSpace()
        {
            if (radius >= 0)
            {
                return pai * radius * radius;
            }
            else
            {
                throw new Exception("error");
            }
            
        }
        public double op_radius
        {
            get
            {
                return radius;
            }
            set
            {
                if (value >= 0)
                {
                    radius = value;
                    space = freshSpace();
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
        public double op_space
        {
            get
            {
                return space;
            }
            set
            {
                if (value >= 0)
                {
                    space = value;
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
    }
    public class Triangle:Graghics
    {
        private double one,two,three;//三条边
        private double space;
        public Triangle()
        {
            one = two = three = 0;
            space = freshSpace();
        }
        public Triangle(double one ,double two ,double three)
        {
            this.one = one;
            this.two = two;
            this.three = three;
            space = freshSpace();
        }
        public double freshSpace()
        {
            if (one == 0|| two ==0|| three == 0)//只要有一边长度为0，面积就为0
            {
                return 0;
            }
            //三边都有值
            if (one + two <= three || one + three <= two || two + three <= one)//如果不满足三角形三边规律
            {
                throw new Exception("triangleError");
            }
            return (System.Math.Sqrt((one + two + three) * (one + two - three) * (one + three - two) * (two + three - one)))/4.0;

        }
        public double op_one
        {
            get
            {
                return one;
            }
            set
            {
                if (value >= 0)
                {
                    one = value;
                    freshSpace();
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
        public double op_two
        {
            get
            {
                return two;
            }
            set
            {
                if (value >= 0)
                {
                    two = value;
                    freshSpace();
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
        public double op_three
        {
            get
            {
                return three;
            }
            set
            {
                if (value >= 0)
                {
                    three = value;
                    freshSpace();
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }

        public double op_space
        {
            get
            {
                return space;
            }
            set
            {
                if (value >= 0)
                {
                    space = value;
                }
                else
                {
                    throw new Exception("error");
                }
            }
        }
    }

    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
